<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <link rel="stylesheet" type="text/css" href="https://a.amap.com/jsapi_demos/static/demo-center/css/prety-json.css">
    <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main1119.css"/>
    <script type="text/javascript">
        window._AMapSecurityConfig = {
            securityJsCode:'b9ba28769560d74a4851d69b3f1f0ce2',
        }
    </script>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=a58ed7280145bdd91cc9a18780d92fd9"></script>
    <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
    <style>
        html,
        body,
        #container {
            width: 100%;
            height: 100%;
        }
        #panel {
            position: absolute;
            background-color: white;
            max-height: 90%;
            overflow-y: auto;
            top: 10px;
            right: 10px;
            width: 280px;
        }
        .btn{
            width:10rem;
            margin-left:6.8rem;
        }
    </style>
    <title>获取搜索信息</title>
</head>
<body>
<div id="container"></div>
<div id="panel"></div>

<!--<div class="input-card" style='width:28rem;'>
    <label style='color:grey'>地理编码，根据地址获取经纬度坐标</label>
    <div class="input-item">
            <div class="input-item-prepend"><span class="input-item-text" >地址</span></div>
            <input id='address' type="text" value='北京市朝阳区阜荣街10号' >
    </div>
    <div class="input-item">
            <div class="input-item-prepend"><span class="input-item-text">经纬度</span></div>
            <input id='lnglat' disabled type="text">
    </div>
    <input id="geo" type="button" class="btn" value="地址 -> 经纬度" />
</div>

<div class="info">
  <h4>搜索结果展示</h4>
  <p><span id="input-info"></span></p>
</div>-->

<script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>


<script src="https://webapi.amap.com/maps?v=1.4.15&key=a58ed7280145bdd91cc9a18780d92fd9&plugin=AMap.PlaceSearch"></script>
<script type="text/javascript" src="https://a.amap.com/jsapi_demos/static/demo-center/js/jquery-1.11.1.min.js" ></script>
<script type="text/javascript" src="https://a.amap.com/jsapi_demos/static/demo-center/js/underscore-min.js" ></script>
<script type="text/javascript" src="https://a.amap.com/jsapi_demos/static/demo-center/js/backbone-min.js" ></script>
<script type="text/javascript" src='https://a.amap.com/jsapi_demos/static/demo-center/js/prety-json.js'></script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=a58ed7280145bdd91cc9a18780d92fd9&plugin=AMap.Geocoder"></script>
<script src="qwebchannel.js"></script>
<script type="text/javascript">
    var map = new AMap.Map("container", {
        resizeEnable: true,
        zoom:1 //初始化地图层级
            <!--         center: [116.397428, 39.90923] //初始化地图中心点-->
    });
    var geocoder = new AMap.Geocoder({
//        city: "010", //城市设为北京，默认：“全国”
    });

    var markers = [];
    var i=0;


    function dele(){
        while(i!=0){
            markers.pop();
            i--;
        }
        window.location.reload();
    }

    function geoCode(address) {
        var marker = new AMap.Marker();
//        var address  = document.getElementById('address').value;
        geocoder.getLocation(address, function(status, result) {
            if (status === 'complete'&&result.geocodes.length) {
                var lnglat = result.geocodes[0].location
//                document.getElementById('lnglat').value = lnglat;
                marker.setPosition(lnglat);
                markers.push(marker);
                i++;
                map.add(marker);
//                map.setFitView(marker);
            }else{
                log.error('根据地址查询位置失败');
            }
        });
    }
    //    document.getElementById("geo").onclick = geoCode;
    //    document.getElementById('address').onkeydown = function(e) {
    //        if (e.keyCode === 13) {
    //            geoCode();
    //            return false;
    //        }
    //        return true;
    //    };


    var mchannel;
    window.onload=function(){

        if (typeof qt != 'undefined')
        {
            new QWebChannel(qt.webChannelTransport, function(channel)
                {
                    channel.objects.qtChannel.cityChanged.connect(geoCode);
                    channel.objects.qtChannel.delchange.connect(dele);
                    mchannel=channel;
                }
            );
        }
        else
        {
            alert("qt对象获取失败！");
        }

    }

</script>
</body>
</html>

